<template>
  <el-dialog :visible.sync="visible" v-dialogDrag :title="title" :close-on-click-modal="false" class="tl-dialog" width="900px" @open="open" @close="close">
    <el-form class="tl-form" ref="form" :model="model" :rules="rules" label-width="150px" :disabled="disableEditSubmit">
      <el-row>
        <el-col :span="24">
          <el-form-item label="姓名" prop="username" :rules="rules.validateRequire">
            <tl-ref-user v-model="model.usercode" :initDisplayData.sync="model.username" :disabled="false" @confirm="userConfirm" dataType="code"></tl-ref-user>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="工号" prop="usercode">
            <el-input v-model="model.usercode" :disabled="true"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <!-- <el-col :span="12">
          <el-form-item label="组件档案id" prop="componentid">
            <el-input v-model="model.componentid"></el-input>
          </el-form-item>
        </el-col> -->
        <el-col :span="24">
          <el-form-item label="组件名称" prop="component" :rules="rules.validateRequire">
            <el-input v-model="model.component" :disabled="true" class="tl-ref-selector">
              <el-button slot="append" type="primary" icon="el-icon-search" @click="openmpmComponentRefData" :isSingleSelect="true"></el-button>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="位置" prop="position">
            <el-input v-model="model.position" :disabled="true"></el-input>
            <!-- <el-select v-model="model.position" filterable clearable>
              <el-option v-for="item in codeModel.positionList" :key="item.code" :label="item.name" :value="item.code" />
            </el-select> -->
          </el-form-item>
        </el-col>
        <!-- <el-col :span="12">
          <el-form-item label="优先级" prop="priority">
            <el-input v-model="model.priority"></el-input>
          </el-form-item>
        </el-col> -->
        <!-- <el-col :span="12">
          <el-form-item label="级别" prop="recordlevel">
            <el-select v-model="model.recordlevel" filterable clearable>
              <el-option v-for="item in codeModel.recordlevelList" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
          </el-form-item>
        </el-col> -->
      </el-row>
      <el-row>
        <!-- <el-col :span="12">
          <el-form-item label="组织编码" prop="orgcode">
            <el-input v-model="model.orgcode"></el-input>
          </el-form-item>
        </el-col> -->
      </el-row>
      <el-row>
        <!-- <el-col :span="12">
          <el-form-item label="角色" prop="rolecode">
            <el-input v-model="model.rolecode"></el-input>
          </el-form-item>
        </el-col> -->

      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="备注" prop="description">
            <el-input v-model="model.description" type="textarea" :rows="4"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>

      </el-row>
      <!-- <el-row>
				<el-col :span="12">
					<el-form-item label="排序码" prop="sortcode">
						<el-input-number v-model="model.sortcode" controls-position="right" :step="1" :min="0" style="width:100%"></el-input-number>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="有效" prop="enabled">
						<el-radio-group v-model="model.enabled">
							<el-radio :label="parseInt(item.code)" v-for="item in codeModel.enabledList" :key="item.code">{{ item.name }}</el-radio>
						</el-radio-group>
					</el-form-item>
				</el-col>
			</el-row> -->
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button :type="disableEditSubmit === false ? 'text' : 'primary'" @click="doCancelEdit">取消</el-button>
      <el-button type="primary" @click="doSubmitEdit" :loading="saveLoading" v-if="disableEditSubmit === false">确认</el-button>
    </div>
    <tlmpm-component-ref ref="mpmComponentRef" @confirm="getmpmComponentRefData" :isSingleSelect="true"></tlmpm-component-ref>
  </el-dialog>
</template>

<script>
/** mixins */
import { mixin_edit } from '@tapui/mixins/mixin_edit'
/** 子组件 */
import tlmpmComponentRef from '@/views/mpm/mpmDataBoardComponentAchives/refList'
/** 工具类 */
import { putAction, getAction, postAction, deleteAction } from '@tapui/utils/http'
/** VUE配置 */
export default {
  mixins: [mixin_edit],
  components: { tlmpmComponentRef },
  data() {
    return {
      moduleTitle: '数据看板自定义记录表',
      urlPrefix: '/mpm/dataBoardCustomizeRecord/',
      url: {
        // 额外的url
      }
    }
  },
  props: {
    position: String
  },
  methods: {
    assignDefaultValue() {
      if (this.isAdd) {
        this.$set(this.model, 'recordlevel', 0)
      }
    },
    /* 打开序列参照*/
    openmpmComponentRefData() {
      this.$refs.mpmComponentRef.query
      this.$refs.mpmComponentRef.visible = true
    },
    /* 获取序列参照数据*/
    getmpmComponentRefData(selectionRow, selectKey, selectionValue) {
      const { name, id, dispposition } = selectionRow
      this.$set(this.model, "component", name)
      this.$set(this.model, "componentid", id)
      this.$set(this.model, "position", dispposition)
    },
    userConfirm(selectData) {
      var nameList = " "
      var usercodeList = " "
      selectData.forEach(element => {
        const { code, dispdeptid, name, deptid, orgid } = element
        nameList += name + ","
        usercodeList += code + ","
      })
      nameList = nameList.substring(0, nameList.lastIndexOf(','))
      usercodeList = usercodeList.substring(0, usercodeList.lastIndexOf(','))
      this.$set(this.model, 'username', nameList)
      this.$set(this.model, 'usercode', usercodeList)
      this.$set(this.model, 'userList', selectData)
    },
    loaded() {
      // 页面加载完毕执行
    }
    // beforeSubmit() {
    //   if (this.model.priority > '888') {
    //     this.$tap.alert('优先级不得大于888!', 'warning')
    //     return false
    //   }
    //   return true
    // }
  }
}
</script>

